import { deleteArticle, getArticleById } from "../../service/article"; import { requireUser, delCache } from "#server/utils/context"; export default defineWrappedResponseHandler(async (event) => { await requireUser(event); const idParam = getRouterParam(event, "id"); if (!idParam) return R.throwError(400, "缺少文章 ID", null); const id = parseInt(idParam); if (isNaN(id)) return R.throwError(400, "文章 ID 格式不正确", null); const existing = await getArticleById(id); if (!existing) return R.throwError(404, "文章不存在", null); // Clear card caches for all associated cards before deleting if (existing.cards.length > 0) { await Promise.all( existing.cards.map((c) => delCache(`card:${c.id}`)), ); } await deleteArticle(id); return R.success(null); });